package cn.itcast.bos.web.action.base;

import java.util.List;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionContext;

import cn.itcast.bos.domain.base.TakeTime;
import cn.itcast.bos.service.base.TakeTimeService;
import cn.itcast.bos.web.action.common.BaseAction;
@Namespace("/")
@Controller
@ParentPackage("json-default")
@Scope("prototype")
public class TakeTimeAction extends BaseAction<TakeTime>{

	@Autowired
	private TakeTimeService takeTimeService;
	
	@Action(value="taketime_findAll",results={@Result(name="success",type="json")})
	public String taketime_findAll() {
		List<TakeTime> takeTimes=takeTimeService.taketime_findAll();
		ActionContext.getContext().getValueStack().push(takeTimes);
		return SUCCESS;
	}
	
	//分页查询收派时间
	@Action(value="takeTime_pageQuery",results={@Result(name="success",type="json")})
	public String takeTimePageQuery() {
		Pageable pageable=new PageRequest(page-1, rows);
		Page<TakeTime> takeTimes=takeTimeService.takeTimePageQuery(pageable);
		
		pushPageDataToValueStack(takeTimes);
		return SUCCESS;
	}
	
	//保存操作
	@Action(value="takeTime_save",results={@Result(name="success",location="./pages/base/take_time.html",type="redirect")})
	public String takeTimeSave() {
		takeTimeService.takeTimeSave(model);
		return SUCCESS;
	}
	
	private String ids;
	
	public void setIds(String ids) {
		this.ids = ids;
	}

	//时间上的进行逻辑除，应对春冬制度
	@Action(value="takeTime_updateStatusDel",results={@Result(name="success",location="./pages/base/take_time.html",type="redirect")})
	public String updateStatus() {
		//逻辑删除
		takeTimeService.updateStatusDel(ids);
		return SUCCESS;
	}
	
	
	//逻辑还原
	@Action(value="takeTime_updateStatusBack",results={@Result(name="success",location="./pages/base/take_time.html",type="redirect")})
	public String updateStatusBack() {
		//逻辑删除
		takeTimeService.updateStatusBack(ids);
		return SUCCESS;
	}
}
